var moment = require("moment")
var express = require("express");
var router = express.Router();
var { limitedModel } = require("../model/limitedmodel");
/* GET home page. */
router.post("/good/:id", async function (req, res, next) {
    let id = req.params.id;
    console.log(id, "idddddddddddd");
    let data = [];
    if (id == 1) {
      data = await limitedModel.find().populate("good");

    } else {
      data = await limitedModel.find({ classid: id }).populate("good");
    }
    console.log(data);
    res.send({
      code: 200,
      data,
    });
  });
  router.get("/time", async function (req, res, next) {
    let times = new Date()

    let data = await limitedModel.find({done:true}).sort({startTime:1}).limit(1).populate('good')
    // data.sort((a,b)=> new Date(a.startTime).getTime()-new Date(b.startTime).getTime())
    // console.log(data);
    res.send({
      code: 200,
      data,
    });
  });
  router.post("/time",async(req,res)=>{
    let id=req.body._id
    let data=await limitedModel.updateOne({_id:id},{$set:{done:false}})
    res.send("删除成功")
  })
module.exports = router;